#include <REGX52.H>	//PPT103AT24C02数据帧
#include "I2C.h"
#define SLAVE_ADDRESSW	0xA0

void AT24C02_WriteByte(unsigned char WordAddress,Data)//字节写
	//第一个表示要写入字节地址，第二个表示要写入的数据，最大都为256
{
	I2C_Start();
	I2C_SendByte(SLAVE_ADDRESSW);
	I2C_ReceiveAck();
	I2C_SendByte(WordAddress);
	I2C_ReceiveAck();
	I2C_SendByte(Data);
	I2C_ReceiveAck();
	I2C_Stop();
}

unsigned char AT24C02_ReadByte(unsigned char WordAddress)//随机读
	//表示要读出字节地址
{
	unsigned char Data;
	I2C_Start();
	I2C_SendByte(SLAVE_ADDRESSW);
	I2C_ReceiveAck();
	I2C_SendByte(WordAddress);
	I2C_ReceiveAck();
	I2C_Start();
	I2C_SendByte(SLAVE_ADDRESSW|0x01);
	I2C_ReceiveAck();
	Data=I2C_ReceiveByte();
	I2C_SendAck(1);
	I2C_Stop();
	return Data;
}